<?php

namespace App\Enums;

enum TradeStatus: string
{
    /**
     * 已支付
     */
    case Payed = "payed";

    /**
     * 等待支付，需要二次查询
     */
    case Waiting = "waiting";

    /**
     * 已创建，等待支付信息
     */
    case Created = 'created';

    /**
     * 已取消，手动&自动
     */
    case Cancel = 'cancel';

    /**
     * 已退款
     */
    case Refund = 'refund';

    /**
     * 挂单
     */
    case Pending = 'pending';

    /**
     * 结开
     */
    case PendingOpen = 'pending_open';

    public function canPay()
    {
        if (in_array($this, [self::Created, self::Pending, self::PendingOpen]))
            return true;

        return false;
    }

    public function canDone()
    {
        if (in_array($this, [self::Created, self::Waiting]))
            return true;

        return false;
    }

    public function label()
    {
        return match ($this) {
            self::Created => '待支付',
            self::Payed => '已支付',
            self::Cancel => '已取消',
            self::Refund => '已退款',
            self::Waiting => '等待确认',
            self::Pending => '挂单',
            self::PendingOpen => '结开',
        };
    }
}
